﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class xuesheng_list : System.Web.UI.Page
{

    string s_where, s_order;
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["sTittle"] = "机构列表";

        string role = Session["sRole"].ToString().Trim();
        if(role != "管理员")
        {
            DropDownList1.Visible = false;
            jigouLabel.Visible = false;
        }
        if (!IsPostBack)
        {
            DataBrid();
        }


    }

    //数据绑定
    private void DataBrid()
    {
        string strWhere = string.Empty;
        if (Session["sJigou"] == null)
        {
            Response.End();
        }
        string zjigou = Session["sJigou"].ToString().Trim();
        string role = Session["sRole"].ToString().Trim();
        switch (role)
        {
            case "学员":
            case "老师":
            case "机构":
                strWhere = " and jigou='" + zjigou + "'";
                break;
        }
        int record = 0;
        int count = 0;
        s_order = "ORDER BY [id] DESC";
        s_where = " where role='学员'";
        string sqlText = " [id],[username1], [grjj], [gzdw], [jigou],[city],[email],[mobile],[chuzhi],[yiskf],[mobile]";
        DataTable DT = DbHelper.ExecutePage(sqlText, "[account]" + s_where + strWhere, "id", s_order, Pager.CurrentPageIndex, Pager.PageSize, out record, out count, null);
        Pager.RecordCount = record;
        this.GridView1.DataSource = DT;
        this.GridView1.DataBind();
    }




    //带搜索条件绑定
    private void DataBrid( string sqlwhere)
    {
        int record = 0;
        int count = 0;
        s_order = "ORDER BY [id] DESC";
        string sqlText = " [id],[username1], [grjj], [gzdw], [jigou],[city],[email],[mobile],[chuzhi],[yiskf]";
        DataTable DT = DbHelper.ExecutePage(sqlText, "[account]" + sqlwhere, "id", s_order, Pager.CurrentPageIndex, Pager.PageSize, out record, out count, null);
        Pager.RecordCount = record;
        this.GridView1.DataSource = DT;
        this.GridView1.DataBind();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)    //自动编号功能
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    //当鼠标停留时更改背景色
        //    e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#80BA21'");
        //    //当鼠标移开时还原背景色
        //    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
        //}
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string zjigou = Session["sJigou"].ToString().Trim();
        string strWhere = " where role='学员'";
        string role = Session["sRole"].ToString().Trim();
        switch (role)
        {
            case "学员":
            case "老师":
            case "机构":
                strWhere += " and jigou='" + zjigou + "'";
                break;
        }
        if(DropDownList1.SelectedValue != "0")
        {
            strWhere += " and jigou='" + DropDownList1.SelectedValue + "'";
        }
        if (!string.IsNullOrEmpty(teacherName.Text))
        {
            strWhere += " and username1 like '%" + teacherName.Text + "%'";
        }
        if (!string.IsNullOrEmpty(teacherPhone.Text))
        {
            strWhere += " and mobile like '%" + teacherPhone.Text + "%'";
        }
        if (strWhere != " where role='学员'")
        {
            Pager.CurrentPageIndex = 0;
            DataBrid(strWhere);
            ViewState["sqlwhere"] = strWhere;
        }
        else
        {
            ViewState["sqlwhere"] = null;
            Pager.CurrentPageIndex = 0;
            DataBrid();
        }
    }

    protected void pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        Pager.CurrentPageIndex = e.NewPageIndex;
        if (ViewState["sqlwhere"] != null)
        {
            DataBrid(ViewState["sqlwhere"].ToString());
        }
        else
        {
            DataBrid();
        }
    
    }
}
